#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
 struct TreeNode {
	int val;
	struct TreeNode* left;
	struct TreeNode* right;
};

 int sumOfLeftLeaves(struct TreeNode* root) {
     if (root == NULL)
     {
         return 0;
     }

     int sum = 0;
     if (root->left && root->left->left == NULL &&
         root->left->right == NULL)
     {
         sum = root->left->val;
     }

     return sum + sumOfLeftLeaves(root->left) +
         sumOfLeftLeaves(root->right);
 }

 struct ListNode
 {
     int val;
     struct ListNode* next;
 };

#include <assert.h>
 typedef struct ListNode ListNode;

 ListNode* buyNode(int x)
 {
     ListNode* newnode = (ListNode*)malloc(sizeof(ListNode));
     assert(newnode);

     newnode->val = x;
     newnode->next = NULL;

     return newnode;
 }

 ListNode* createList(int n)
 {
     ListNode* phead, * ptail;
     int i = 1;
     phead = ptail = buyNode(i++);
     while (i <= n)
     {
         ptail->next = buyNode(i++);
         ptail = ptail->next;
     }
     ptail->next = phead;
     return phead;
 }

 int ysf(int n, int m) {
     ListNode* head = createList(n);
     ListNode* cur = head;
     ListNode* prev = NULL;
     int i = 1;
     while (cur->next != cur)
     {
         if (i == m)
         {
             prev->next = cur->next;
             free(cur);
             cur = prev->next;
             i = 1;
         }

         else
         {
             prev = cur;
             cur = cur->next;
             i++;
         }
     }

     return cur->val;
 }


